import os
from hashlib import md5


def md5_file(file_):
    with open(file_, 'rb') as f:
        m = md5()
        m.update(f.read())
        return m.hexdigest()


def get_kv_wen_jian_md5(code_dir):
    data = {}
    for root, _, files in os.walk(code_dir):
        for file_ in files:
            file_path = os.path.join(root, file_)
            if '.git' in file_path or '.vscode' in file_path or '__pycache__' in file_path or file_.startswith('.'):
                continue
            # 将文件进行md5加密
            file_md5 = md5_file(file_path)
            file_path_arr = file_path.split('/')
            file_path_arr = file_path_arr[3:]
            file_path = '/'.join(file_path_arr)
            data[file_path] = file_md5
    return data


def check_project(code_dir):
    return get_kv_wen_jian_md5(code_dir)
